<?php

namespace App\Http\Requests\Api;

use Illuminate\Foundation\Http\FormRequest;

class UserRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        switch ($this->method()) {
            case 'POST':
                return [
                    /*用户注册需要传递4个字段
                    name password verify_key(短信验证码接口返回的key) verify_code 短信验证码
                    */
                    'name' => 'required|string|between:3,25',
                    'password' => 'required|string|min:6',
                    'verify_key' => 'required|string',
                    'verify_code' => 'required|string'
                ];
                break;
            case 'PATCH':
                return [
                    //用户资料更新,字段不一定
                    'name'=>'between:3,25|regex:/^[A-Za-z0-9\-\_]+$/|unique:users,name',
                    'email'=>'email',
                    'avatar_image_id'=>'exists:images,id'
                ];
                break;
        }

    }

    public function attributes()
    {
        return [
            'verify_key' => '短信验证码 key',
            'verify_code' => '短信验证码'
        ];
    }

}
